<template>
  <div class="app-container pages">
<div class="main-search">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px" class="main-search">
      <el-form-item label="客户姓名" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入客户姓名" clearable @keyup.enter.native="handleQuery"
                  style="width: 160px"/>
      </el-form-item>
      <el-form-item label="部门" prop="deptId">
        <treeselect v-model="queryParams.deptId" :options="deptOptions" :show-count="true" style="width: 160px"
                    placeholder="请选择归属部门" @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="客户电话" prop="tel">
        <el-input v-model="queryParams.tel" placeholder="请输入客户电话" clearable @keyup.enter.native="handleQuery"
                  style="width: 160px"/>
      </el-form-item>
      <el-form-item label="客户状态" prop="customerStatus">
        <el-select v-model="queryParams.customerStatus" placeholder="请选择客户状态" clearable style="width: 160px">
          <el-option v-for="dict in dict.type.customer_status" :key="dict.value"
                     :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="公司状态" prop="companyStatus">
        <el-select v-model="queryParams.companyStatus" placeholder="请选择公司状态" clearable style="width: 160px">
          <el-option v-for="dict in dict.type.company_status" :key="dict.value"
                     :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="星级" prop="level">
        <el-select v-model="queryParams.level" placeholder="请选择星级" clearable style="width: 160px">
          <el-option v-for="dict in dict.type.level_type" :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="贷款类型" prop="loanType">
        <el-select v-model="queryParams.loanType" placeholder="请选择贷款类型" clearable style="width: 160px">
          <el-option v-for="dict in dict.type.loan_type" :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="未更新" prop="notUpdateDay">
        <el-input v-model="queryParams.notUpdateDay" type="number" placeholder="未更新超过天数" clearable
                  @keyup.enter.native="handleQuery"
                  style="width: 160px"/>
      </el-form-item>
      <el-form-item label="时间" prop="timeInfo">
        <el-select v-model="queryParams.timeType" placeholder="不限" clearable style="width: 80px">
          <el-option
            v-for="dict in dict.type.time_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
        <el-select v-model="queryParams.applyTimeScope" placeholder="不限" clearable style="width: 80px"
                   @change="applyTimeScopeChange">
          <el-option
            v-for="dict in dict.type.apply_time_scope"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="开始时间" prop="startTime" v-if="queryParams.applyTimeScope == 99">
        <el-date-picker
          v-model="queryParams.startTime"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetime"
          :clearable="false"
          :editable="false"
          placeholder="请选择开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime" v-if="queryParams.applyTimeScope == 99">
        <el-date-picker
          v-model="queryParams.endTime"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetime"
          :clearable="false"
          :editable="false"
          placeholder="请选择结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="重要客户" prop="vip">
        <el-select v-model="queryParams.vip" placeholder="-不限-" clearable style="width: 160px">
          <el-option
            v-for="dict in dict.type.is_vip"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="贷款额度" prop="applyMoney">
        <el-select v-model="queryParams.applyMoney" placeholder="-不限-" clearable style="width: 160px">
          <el-option
            v-for="dict in dict.type.quota_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="备注" prop="bz">
        <el-input v-model="queryParams.bz" placeholder="-不限-" clearable @keyup.enter.native="handleQuery"
                  style="width: 160px"/>
      </el-form-item>
      <el-form-item label="房产" prop="house">
        <el-select v-model="queryParams.house" placeholder="-不限-" clearable style="width: 160px">
          <el-option
            v-for="dict in dict.type.house_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="来源" prop="source">
        <el-input v-model="queryParams.source" placeholder="-不限-" clearable @keyup.enter.native="handleQuery"
                  style="width: 160px"/>
<!--        <el-select v-model="queryParams.source" placeholder="-不限-" clearable style="width: 160px">-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.source_type"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
      </el-form-item>
      <el-form-item label="公积金" prop="fund">
        <el-select v-model="queryParams.fund" placeholder="-不限-" clearable style="width: 160px">
          <el-option
            v-for="dict in dict.type.fund_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="再审件" prop="revieweFlag">
        <el-select v-model="queryParams.revieweFlag" placeholder="-不限-" clearable style="width: 160px">
          <el-option
            v-for="dict in dict.type.is_vip"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="批次" prop="batchLogo">
        <el-input v-model="queryParams.batchLogo" placeholder="-不限-" clearable @keyup.enter.native="handleQuery"
                  style="width: 160px"/>
      </el-form-item>
      <el-form-item label="渠道API" prop="channelId">
        <el-select v-model="queryParams.channelId" placeholder="-不限-" clearable style="width: 160px">
          <el-option
            v-for="dict in this.channelDataList"
            :key="dict.id + ''"
            :label="dict.channelName"
            :value="dict.id + ''"
          />
        </el-select>
      </el-form-item>
      <el-row>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['customer:myCustomer:add']"
        >新增
        </el-button>
        <el-button
          type="info"
          plain
          size="mini"
          @click="bathDistributionCustomer"
          v-hasPermi="['customer:pool:allot']"
        >批量分配
        </el-button>
        <el-button
          type="info"
          plain
          size="mini"
          v-if="this.deptParentId != 0"
          @click="bathCustomerReturn"
          v-hasPermi="['customer:pool:return']"
        >批量退回
        </el-button>
        <el-button
          type="info"
          plain
          size="mini"
          @click="bathReturnTotalCutomer"
          v-hasPermi="['customer:pool:gotoTotalCustomer']"
        >退回总表
        </el-button>
        <el-button
          type="info"
          plain
          @click="handlePull"
          v-if="deptParentId != 0"
          v-hasPermi="['customer:pool:deptPull']"
        >拉取
        </el-button>
      </el-row>
    </el-form>
</div>

    <div class="main-body">
      <div class="main-table">
    <el-table v-loading="loading" :data="customerList" size="mini"
              @selection-change="handleSelectionChange" border @cell-click="cellClick"
              @sort-change="sortChange"
              :default-sort="{prop: 'lastRemarkTime', order: 'descending'}">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="ID" align="center" prop="id" v-if="false"/>
      <el-table-column label="姓名" align="center" prop="name" width="100px" fixed="left"/>
      <el-table-column label="状态" align="center" prop="customerStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.customer_status" :value="scope.row.customerStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="公司状态" align="center" prop="companyStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.company_status" :value="scope.row.companyStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="星级" align="center" prop="level">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.level_type" :value="scope.row.level"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="bz" width="400px">
        <template slot-scope="scope">
          <div class="messageCard" v-html="scope.row.bz">
          </div>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="lastRemarkTime" width="100"
                       sortable="custom"
                       :sort-orders="['descending', 'ascending']">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastRemarkTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="顾问" align="center" prop="busName"/>
      <el-table-column label="部门" align="center" prop="deptName"/>
      <!--      <el-table-column label="所属部门" align="center" prop="deptName"/>-->
      <el-table-column label="年龄" align="center" prop="age"/>
      <el-table-column label="性别" align="center" prop="sex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sex_type" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="房" align="center" prop="house">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.house_type" :value="scope.row.house"/>
        </template>
      </el-table-column>
      <el-table-column label="车" align="center" prop="car">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.car_type" :value="scope.row.car"/>
        </template>
      </el-table-column>
      <el-table-column label="保单" align="center" prop="warranty">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.warranty_type" :value="scope.row.warranty"/>
        </template>
      </el-table-column>
      <el-table-column label="社保" align="center" prop="insurance">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.insurance_type" :value="scope.row.insurance"/>
        </template>
      </el-table-column>
      <el-table-column label="公积金" align="center" prop="fund">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.fund_type" :value="scope.row.fund"/>
        </template>
      </el-table-column>
      <el-table-column label="申请额度" align="center" prop="applyMoney"/>
      <el-table-column label="进系统时间" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="贷款类型" align="center" prop="loanType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.loan_type" :value="scope.row.loanType"/>
        </template>
      </el-table-column>
      <el-table-column label="来源" align="center" prop="source">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.source_type" :value="scope.row.source"/>
        </template>
      </el-table-column>
      <el-table-column label="批次" align="center" prop="batchLogo"/>
      <!--      <el-table-column label="城市" align="center" prop="regionName"/>-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="150px">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click.stop="handleUpdate(scope.row)"
            v-hasPermi="['customer:pool:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click.stop="distributionCustomer(scope.row)"
            v-hasPermi="['customer:pool:allot']"
          >分配
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click.stop="customerReturn(scope.row)"
            v-if="scope.row.parentDeptId != 0 || deptParentId != 0"
            v-hasPermi="['customer:pool:return']"
          >退回
          </el-button>
        </template>
      </el-table-column>
    </el-table>
      </div>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </div>

    <!-- 添加或修改客户信息对话框 -->
    <el-dialog :title="title" :visible.sync="insertOpen" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px" :style="{'--form-item-width': '50%'}">
        <el-row>
          <el-col :span="12">
            <el-form-item label="姓名" prop="name">
              <el-input v-model="form.name" placeholder="请输入姓名"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户电话" prop="tel">
              <el-input v-model="form.tel" maxlength="20" :disabled="isEdit" placeholder="请输入客户电话"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <!--          <el-col :span="12">-->
          <!--            <el-form-item label="所属部门" prop="distributeDeptId" v-if="isEdit">-->
          <!--              <el-select v-model="form.distributeDeptId" placeholder="请选择归属部门" :disabled="isEdit">-->
          <!--                <el-option-->
          <!--                  v-for="dict in form.id == null ? this.topDeptList : this.allDeptList"-->
          <!--                  :key="dict.deptId"-->
          <!--                  :label="dict.deptName"-->
          <!--                  :value="dict.deptId"-->
          <!--                ></el-option>-->
          <!--              </el-select>-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->
          <el-col :span="12">
            <el-form-item label="星级" prop="level">
              <el-select v-model="form.level" placeholder="请选择星级">
                <el-option
                  v-for="dict in dict.type.level_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="贷款类型" prop="loanType">
              <el-select v-model="form.loanType" placeholder="请选择贷款类型">
                <el-option
                  v-for="dict in dict.type.loan_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="年龄" prop="age">
              <el-input v-model="form.age" placeholder="请输入年龄"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" prop="sex">
              <el-select v-model="form.sex" placeholder="请选择性别">
                <el-option
                  v-for="dict in dict.type.sex_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="标签" prop="label">
              <el-input v-model="form.label" placeholder="请输入内容"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学历 " prop="education">
              <el-input v-model="form.education" placeholder="请输入学历 "/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="是否有房" prop="house">
              <el-select v-model="form.house" placeholder="请选择是否有房">
                <el-option
                  v-for="dict in dict.type.house_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否有车" prop="car">
              <el-select v-model="form.car" placeholder="请选择是否有车">
                <el-option
                  v-for="dict in dict.type.car_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="保单" prop="warranty">
              <el-select v-model="form.warranty" placeholder="请选择保单">
                <el-option
                  v-for="dict in dict.type.warranty_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="社保" prop="insurance">
              <el-select v-model="form.insurance" placeholder="请选择社保">
                <el-option
                  v-for="dict in dict.type.insurance_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="公积金" prop="fund">
              <el-select v-model="form.fund" placeholder="请选择公积金">
                <el-option
                  v-for="dict in dict.type.fund_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工资" prop="salary">
              <el-input v-model="form.salary" placeholder="请输入工资"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="申请额度" prop="applyMoney">
              <el-input v-model="form.applyMoney" placeholder="请输入申请额度"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="省份" prop="province">
              <el-select v-model="form.province" placeholder="请选择省份" @clear="clearSelect('1','f')" clearable>
                <el-option
                  @click.native="getChildren(p.code,'1','f')"
                  v-for="p in this.provinceList"
                  :key="p.code"
                  :label="p.name"
                  :value="p.code"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="城市" prop="city">
              <el-select v-model="form.city" placeholder="请选择城市" @clear="clearSelect('2','f')" clearable>
                <el-option
                  @click.native="getChildren(p.code,'2','f')"
                  v-for="p in this.formCityList"
                  :key="p.code"
                  :label="p.name"
                  :value="p.code"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="区县" prop="county">
              <el-select v-model="form.county" placeholder="请选择区县" clearable>
                <el-option
                  v-for="p in this.formCountyList"
                  :key="p.code"
                  :label="p.name"
                  :value="p.code"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="客户经理" prop="manager">
              <el-input v-model="form.manager" placeholder="请输入客户经理"/>
            </el-form-item>
          </el-col>


          <el-col :span="12">
            <el-form-item label="实际申请时间" prop="realityApplyTime">
              <el-date-picker
                v-model="form.realityApplyTime"
                format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="datetime"
                :clearable="false"
                :editable="false"
                placeholder="请选择实际申请时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="备注" prop="bz">
          <el-input v-model="form.bz" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="insertSubmit">确 定</el-button>
        <el-button @click="insertOpen=false">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 添加或修改客户信息对话框 -->
    <el-drawer :title="title" :visible.sync="open" size="60%" style="height: 100vh" append-to-body @close="closeDialog">
      <CustomerDetail :getList="getList" :recordList="recordList" :getCustomerChangeList="getCustomerChangeList"  ref="customerDetail" :currentType="currentType"
                      :bzRecordList="bzRecordList" :commentRecordList="commentRecordList"
                      :form="form" :pushRecordList="pushRecordList" :returnRecordList="returnRecordList"
                      :channelCustomerList="channelCustomerList"
                      :customerChangeList="customerChangeList"></CustomerDetail>
      <div class="pop-footer">
        <el-button size="mini" plain type="primary" @click="handlePrevious">上一篇</el-button>
        <el-button size="mini" plain type="primary" @click="handleNext">下一篇</el-button>
        <!-- :loading="buttonLoading"        -->
        <el-button size="mini" type="primary" @click="submitForm">确 定</el-button>
        <el-button size="mini" @click="cancel">关闭</el-button>
      </div>
    </el-drawer>


    <!-- 分配客户信息 -->
    <bath-dis-customer ref="bathDisCustomer"></bath-dis-customer>
    <!-- 退回原因    -->
    <back-return ref="backReturn"></back-return>
    <!-- 拉取客户信息 -->
    <pull-superior-customer ref="pullSuperiorCustomer"></pull-superior-customer>

  </div>
</template>

<script>
import {
  getCustomer,
  delCustomer,
  addCustomer,
  updateCustomer,
  loadParentOrg, getRecordList, pushCustomerRecord, returnCustomerRecord
} from "@/api/customer/customer";
import PullSuperiorCustomer from "@/views/components/PullSuperiorCustomer.vue";
import {getDeptInfoList, customerPoolList, checkStatus,} from "@/api/customerPool/customerPool"
import BathDisCustomer from '../components/BathDisCustomer.vue'
import BackReturn from "@/views/components/BackReturn.vue";
import {getToken} from "@/utils/auth";
import {deptTreeSelect} from "@/api/system/user";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import CustomerDetail from "@/components/CustomerDetail/index.vue";
import {noListChannelDataConf} from "@/api/channel/channelDataConf";
import {channelCustomerList} from "@/api/channel/channelPushDis";
import {noListCommentRecord} from "@/api/customer/commentRecord";
import {getCustomerInfoChangeList} from "@/api/customer/customerInfoChange";

export default {
  name: "Customer",
  components: {
    CustomerDetail,
    Treeselect,
    BackReturn,
    BathDisCustomer,
    PullSuperiorCustomer
  },
  dicts: ['fund_type', 'customer_status', 'sex_type', 'car_type', 'insurance_type', 'house_type', 'warranty_type',
    'level_type', 'loan_type', 'quota_type', 'company_status', 'is_vip', 'time_type', 'apply_time_scope',
    'source_type'],
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 客户信息表格数据
      customerList: [],
      // 用户信息数据
      userList: [],
      // 部门信息数据
      deptList: [],
      // 顶级部门信息
      topDeptList: [],
      // 所有部门信息
      allDeptList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 分配弹出框
      allotOpen: false,
      // 省级地址
      provinceList: [],
      deptOptions: [],
      // 市区地址
      searchCityList: [],
      // 区县
      searchCountyList: [],
      // 市区地址
      formCityList: [],
      // 区县
      formCountyList: [],
      isEdit: false,
      customerIds: [],
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: {Authorization: "Bearer " + getToken()},
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/customerPool/importData"
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 30,
        name: undefined,
        tel: undefined,
        level: undefined,
        loanType: undefined,
        age: undefined,
        sex: undefined,
        label: undefined,
        education: undefined,
        house: undefined,
        car: undefined,
        warranty: undefined,
        insurance: undefined,
        fund: undefined,
        salary: undefined,
        applyMoney: undefined,
        province: undefined,
        city: undefined,
        county: undefined,
        manager: undefined,
        customerStatus: undefined,
        companyStatus: undefined,
        distributeDeptId: undefined,
        share: undefined,
        source: undefined,
        dataSource: undefined,
        vip: undefined,
        taskId: undefined,
        createDate: undefined,
        bz: undefined,
        notUpdateDay: undefined, // 未超出天数
        timeType: undefined,  // 时间类型
        applyTimeScope: undefined, // 申请时间
        startTime: undefined, // 自定义开始时间
        endTime: undefined, // 自定义结束时间
        revieweFlag: undefined,
        batchLogo: undefined,
        sortInfo: undefined,
        sortRule: undefined,
        channelId: undefined, // 渠道id
      },
      // 记录信息
      bzRecordList: [],
      pushRecordList: [], // 下推记录
      returnRecordList: [], // 退回记录
      commentRecordList: [], // 点评记录
      channelCustomerList: [], // 渠道客户记录
      customerChangeList:[], // 客户信息改变记录
      insertOpen: false,
      currentType: 'customerPool',
      // 上一页 下一页实现
      operList: [], //  全量id  [{id:'1'},{id:'2'}] 这种形式
      index: 0, // 当前页面下标
      pageId: '', // 当前页面id

      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // name: [
        //   {required: true, message: "姓名不能为空", trigger: "blur"}
        // ],
        tel: [
          // {
          //   required: true,
          //   pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
          //   message: "请输入正确格式的手机号码",
          //   trigger: "blur"
          // }
          {required: true, message: "手机号码不能为空", trigger: "blur"}
        ],
        level: [
          {required: true, message: "星级不能为空", trigger: "blur"}
        ],
        name: [
          {required: true, message: "姓名不能为空", trigger: "blur"}
        ],
        loanType: [
          {required: true, message: "贷款类型不能为空", trigger: "blur"}
        ],
        distributeDeptId: [
          {required: true, message: "部门不能为空", trigger: "blur"}
        ],
      },
      deptParentId: undefined,
      // 渠道信息
      channelDataList: [],
    };
  },
  created() {
    this.deptParentId = this.$store.state.user.user.dept.parentId
    this.getList();
    this.getDeptInfoInit('0');
    this.getDeptInfoInit('1');
    this.loadPOrg('0', 0, 's');
    this.getDeptTree();
    this.getChannelDataList();
  },
  methods: {

    // 获取渠道数据信息
    getChannelDataList() {
      noListChannelDataConf().then(res=> {
        this.channelDataList = res.data;
      });
    },

    sortChange(column) {
      console.log(column.prop, column.order, '777')
      const sortInfo = column.prop  //  当前排序的字段
      let order = 'desc';
      if (column.order === 'descending') {
        order = 'desc' // 排序或倒序
      } else {
        order = 'asc' // 排序或倒序
      }
      this.queryParams.sortInfo = sortInfo;
      this.queryParams.sortRule = order;
      this.getList()
      //this.getSmsList()   调用后台查询
    },

    // 上一篇
    handlePrevious() {
      this.index = this.operList.findIndex(item => item.id === this.pageId)
      if (this.index === 0) {
        // 提示已经是第一篇或者禁用上一篇按钮 自由发挥咯
      } else {
        this.pageId = this.operList[this.index - 1].id // 获取上一篇id 在getList()里需要
        this.getInfoList() // 获取详情数据的接口
      }
    },
    // 下一篇
    handleNext() {
      console.log("pageId" + this.pageId);
      this.index = this.operList.findIndex(item => item.id === this.pageId)
      if (this.index >= this.operList.length - 1) {
        // 提示已经是最后一篇或者禁用下一篇按钮 自由发挥咯
      } else {
        this.pageId = this.operList[this.index + 1].id // 获取下一篇id 在getList()里需要
        this.getInfoList() // 获取详情数据的接口
      }
    },

    // 获取详情数据
    getInfoList() {
      this.loading = true;
      this.reset();
      getCustomer(this.pageId).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        // 回选区域信息
        if (this.form.province) {
          this.loadPOrg(this.form.province, 1, "f");
        } else {
          this.searchCityList = [];
        }
        if (this.form.city) {
          this.loadPOrg(this.form.city, 2, "f");
        } else {
          this.searchCountyList = [];
        }
        this.title = "修改客户信息";
      });
      // 获取右侧备注信息
      getRecordList(this.pageId).then(response => {
        this.bzRecordList = response.data;
      })

      this.pushCustomerRecord(this.pageId);
      this.returnCustomerRecord(this.pageId);
      this.getCommentRecordList(this.pageId);
      this.getChannelCustomerList(this.pageId);
      this.getCustomerChangeList(this.pageId);
    },

    /**  日期时间触发改变 */
    applyTimeScopeChange(val) {
      if (val != 99) {
        this.queryParams.startTime = undefined;
        this.queryParams.endTime = undefined;
      }
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then(response => {
        this.deptOptions = response.data;
      });
    },
    /** 获取一级部门信息 */
    getDeptInfoInit(str) {
      if (str === '0') {
        const query = {
          parentId: 0
        }
        getDeptInfoList(query).then(response => {
          this.topDeptList = response.data;
        });
      } else {
        getDeptInfoList().then(response => {
          this.allDeptList = response.data;
        });
      }
    },
    /** 批量退回 */
    bathCustomerReturn() {
      const ids = this.ids;
      if (ids.length < 1) {
        this.$modal.msgError("请选择客户");
        return;
      }
      const customerIds = [];
      ids.forEach(item => {
        const obj = this.customerList.find(it => it.id = item);
        const data = {
          id: obj.id,
          deptId: obj.distributeDeptId
        }
        customerIds.push(data);
      })
      this.$refs.backReturn.openDialog(customerIds, "客户退回", 'pool');
    },
    /** 批量退回公海 */
    bathReturnTotalCutomer() {
      if (this.ids.length == "0") {
        this.$modal.msgError(`请选择客户!`);
        return;
      }
      this.$refs.backReturn.openDialog(this.ids, "退回总池", 'total');
      // bathReturnTotalCutomer(this.ids).then(res=>{
      //     this.$modal.msgSuccess("退回成功!");
      //     this.getList()
      // })
    },
    /** 退回 */
    customerReturn(row) {
      const ids = row.id || this.ids
      const customerIds = [];
      const obj = this.customerList.find(it => it.id = ids)
      const data = {
        id: obj.id,
        deptId: obj.distributeDeptId
      }
      customerIds.push(data);
      this.$refs.backReturn.openDialog(customerIds, "客户退回", 'pool');
    },
    /** 批量分配 **/
    bathDistributionCustomer() {
      const ids = this.ids;
      if (ids.length < 1) {
        this.$modal.msgError("请选择客户");
        return;
      }
      const customerIds = []
      ids.forEach(item => {
        const obj = this.customerList.find(it => it.id === item);
        const data = {
          "id": obj.id,
          "taskId": obj.taskId,
          "name": obj.name
        }
        customerIds.push(data);
      })
      this.$refs.bathDisCustomer.openDialog(customerIds, 'poolCustomer');
    },

    /** 处理分配数据 */
    distributionCustomer(row) {
      const ids = row.id || this.ids
      const customerIds = []
      const obj = this.customerList.find(it => it.id === ids);
      const data = {
        "id": obj.id,
        "taskId": obj.taskId,
        "name": obj.name
      }
      customerIds.push(data);
      this.$refs.bathDisCustomer.openDialog(customerIds, 'poolCustomer');
    },

    /** 加载组织 **/
    loadPOrg(parentId, level, type) {
      loadParentOrg(parentId).then(response => {
        if (level == '0') {
          this.provinceList = response.data
        } else if (level == '1') {
          if (type === 's') {
            this.searchCityList = response.data
          } else {
            this.formCityList = response.data
          }
        } else {
          if (type == 's') {
            this.searchCountyList = response.data
          } else {
            this.formCountyList = response.data
          }
        }
      })
    },
    getChildren(parentId, level, type) {
      this.clearSelect(level, type)
      this.loadPOrg(parentId, level, type)
    },

    clearSelect(level, type) {
      if (type == 's') {
        if (level == '1') {
          this.searchCityList = []
          this.queryParams.city = ''
        }
        this.queryParams.county = ''
        this.searchCountyList = []
      } else {
        if (level == '1') {
          this.formCityList = []
          this.form.city = ''
        }
        this.form.county = ''
        this.formCountyList = []
      }
    },
    /** 查询客户信息列表 */
    getList() {
      //this.loading = true;
      customerPoolList(this.queryParams).then(response => {
        this.customerList = response.rows;
        this.operList = response.rows;
        this.total = response.total;
        // this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        name: undefined,
        tel: undefined,
        level: undefined,
        loanType: undefined,
        age: undefined,
        sex: undefined,
        label: undefined,
        education: undefined,
        house: undefined,
        car: undefined,
        warranty: undefined,
        insurance: undefined,
        fund: undefined,
        salary: undefined,
        applyMoney: undefined,
        province: undefined,
        city: undefined,
        county: undefined,
        remark: undefined,
        manager: undefined,
        customerStatus: undefined,
        companyStatus: undefined,
        distributeDeptId: undefined,
        share: undefined,
        source: undefined,
        dataSource: undefined,
        vip: undefined,
        taskId: undefined,
        createBy: undefined,
        createDate: undefined,
        updateBy: undefined,
        updateTime: undefined,
        bz: undefined,
        realityApplyTime: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      if (this.form.vip) {
        this.form.vip = undefined;
      }
      this.queryParams.applyTimeScope = undefined;
      this.queryParams.timeType = undefined;
      this.queryParams.sortInfo = undefined;
      this.queryParams.sortRule = undefined;
      this.searchCityList = [];
      this.searchCountyList = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 拉取数据 */
    handlePull() {
      this.$refs.pullSuperiorCustomer.openDialog('deptPull');
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.insertOpen = true;
      this.isEdit = false;
      this.title = "添加客户信息";
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "用户导入";
      this.upload.open = true;
    },

    cellClick(row, column, cell, event) {
      if (column.property == 'customerStatus') {
        this.handleUpdate(row)
      }
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      console.log("jinlal")
      this.loading = true;
      this.isEdit = true;
      this.reset();
      const id = row.id || this.ids
      this.pageId = id;
      getCustomer(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        // 回选区域信息
        if (this.form.province) {
          this.loadPOrg(this.form.province, 1, "f");
        } else {
          this.searchCityList = [];
        }
        if (this.form.city) {
          this.loadPOrg(this.form.city, 2, "f");
        } else {
          this.searchCountyList = [];
        }
        this.title = "修改客户信息";
      });
      // 获取右侧信息
      this.recordList(id);
      this.pushCustomerRecord(id);
      this.returnCustomerRecord(id);
      this.getCommentRecordList(id);
      this.getChannelCustomerList(id);
      this.getCustomerChangeList(id);

    },
    /** 下推记录查看 */
    pushCustomerRecord(id) {
      pushCustomerRecord(id).then(res => {
        this.pushRecordList = res.data;
      })
    },

    returnCustomerRecord(id) {
      returnCustomerRecord(id).then(res => {
        this.returnRecordList = res.data;
      })
    },

    getChannelCustomerList(id) {
      const queryWrapper = {
        id: id
      };
      channelCustomerList(queryWrapper).then(res => {
        this.channelCustomerList = res.data;
      })
    },

    getCustomerChangeList(id) {
      const queryWrapper = {
        customerId: id,
        type: 'customerInfoChange'
      };
      getCustomerInfoChangeList(queryWrapper).then(res => {
        this.customerChangeList = res.data;
      })
    },

    getCommentRecordList(id) {
      const queryWrapper = {
        customerId: id
      }
      noListCommentRecord(queryWrapper).then(res => {
        this.commentRecordList = res.data;
      })
    },

    /** 获取右侧跟进记录 */
    recordList(id) {
      // 获取右侧备注信息
      getRecordList(id).then(response => {
        this.bzRecordList = response.data;
      })
    },

    // 新增提交
    insertSubmit() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateCustomer(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addCustomer(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.insertOpen = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs['customerDetail'].btnSubmit();
    },

    /** 审核 */
    handleCheck(row, type) {
      const ids = row.id || this.ids;
      const dataInfo = {
        "id": ids,
        "status": type
      }
      checkStatus(dataInfo).then(resp => {
        this.getList();
        this.$modal.msgSuccess("审核成功");
      })
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除客户信息编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delCustomer(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 修改框 */
    closeDialog() {
      this.open = false;
      this.getList();
    },
    /** 下载模板操作 */
    // importTemplate() {
    //   downloadTemplate().then(response => {
    //     this.baseDownload(response.msg)
    //   }).catch(error => {
    //     console.log(error)
    //   }).finally(() => {
    //     this.reset()
    //   })
    // },
    // 文件上传中处理
    // handleFileUploadProgress(event, file, fileList) {
    //   this.upload.isUploading = true;
    // },
    // 文件上传成功处理
    // handleFileSuccess(response, file, fileList) {
    //   this.upload.open = false;
    //   this.upload.isUploading = false;
    //   this.$refs.upload.clearFiles();
    //   this.$alert(
    //     "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg
    //     + "</div>", "导入结果", {dangerouslyUseHTMLString: true});
    //   this.getList();
    // },
    // 提交上传文件
    // submitFileForm() {
    //   this.$refs.upload.submit();
    // }
  }
};
</script>
<style scoped>
.messageCard {
  overflow-x: hidden;
  overflow-y: scroll;
  word-break: break-all;
  width: 390px;
  max-height: 100px;
  text-align: left;
  float: left;
  text-align: left;
  text-overflow: ellipsis;
  color: #313131;
}

.messageCard::-webkit-scrollbar {
  width: 4px;
}

.messageCard::-webkit-scrollbar-thumb {
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.2);
}

.messageCard::-webkit-scrollbar-track {
  border-radius: 0;
  background: rgba(0, 0, 0, 0.1);
}
</style>
<style type="text/css">
.el-dialog__body {
  padding: 5px 20px 30px 20px;
}

.el-form-item--small.el-form-item {
  margin-bottom: 8px;
}

.el-timeline-item {
  padding-bottom: 1px;
}

.vue-treeselect__control {
  width: auto;
}

.vue-treeselect__value-container,
.vue-treeselect__multi-value {
  width: auto;
  vertical-align: middle;
}

.pop-footer {
  height: 52px;
  width: 100%;
  position: absolute;
  left: 0;
  bottom: 0;
  text-align: center;
  background: #fff;
  z-index: 100;
  border-top: 1px solid #dcdfe6;
  box-shadow: 0px -4px 8px 0px rgba(0, 0, 0, 0.06);

}

.el-button {
  width: 60px;
  height: 32px;
  margin-top: 10px;
  text-align: center;
  padding: 0;
  margin-right: 15px;

}
</style>
